#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
#define maxn 10001
const int INF = 1<<30;

int n,k;
int p[maxn],t[maxn];
int dp[maxn];

int dfs(int s, int taskid){
	if(s>n || taskid>k) return 0;
	if(dp[s]>=0) return dp[s];
	int rs=s;
	while(p[taskid]<s){
		if(taskid<=k) taskid++;
		else return 0;
	}
	s=p[taskid];
	int cminans = INF;
	while(s==p[taskid]){
		int tans = dfs(s+t[taskid], taskid+1)+t[taskid];
		cminans = min(tans, cminans);
		taskid++;
	}
	return dp[rs] = cminans;
}

int main(){
	memset(dp,-1,sizeof(dp));
	cin>>n>>k;
	for(int i=1;i<=k;i++)
		cin>>p[i]>>t[i];

	cout<<n-dfs(1,1)<<endl;
	return 0;
}